package huadi.designpattern.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class DynamicProxy implements InvocationHandler {

	private DynamicProxyTarget target;

	public Object bind(DynamicProxyTarget target) {
		this.target = target;
		return Proxy.newProxyInstance(target.getClass().getClassLoader(),
				target.getClass().getInterfaces(), this);
	}

	@Override
	public Object invoke(Object arg0, Method method, Object[] arg2)
			throws Throwable {
		Object result = null;
		System.out.println("Dynamic before invoke");
		result = method.invoke(this.target, arg2);
		System.out.println("Dynamic after invoke");
		return result;
	}

}
